import {
  getCodeCount,
  getCustomerList,
  getCustomerTypeValueList,
  getQualityTypeList
} from "@/api/print/mesProdOthercode";

export const customerDialog = {
  data() {
    return {
      customerDialogVisible: false, //表格弹框隐藏显示
      getCustomerList, // 获取弹框数据接口
      customerFooter: [
        {
          name: $i18n.t("common.cancel"),
        },
        {
          name: $i18n.t("common.ok"),
          type: 'primary',
          disabled: (data, otherParam) => {
            if (otherParam['isMultiple']) {
              return false;
            } else {
              return data.length !== 1;
            }
          }
        },
      ], // 是否需要底部按钮默认true
      customerSearchConfig: {
        inline: true,
        isShowResetBtn: true,
        formDesc: {
          customerCode: {
            type: "input",
            label: $i18n.t("mesOtherCodePrinting.customerCode"), //"编码",
            attrs: {
              clearable: true,
            },
            layout: 12,
          },
          customerName: {
            type: "input",
            label: $i18n.t("mesOtherCodePrinting.customerName"), //"名称",
            attrs: {
              clearable: true,
            },
            layout: 12,
          },
        },
      },
      customerColumn: [
        {
          type: "selection",
        },
        {
          type: "index",
          align: "center",
          label: $i18n.t("common.order"),
          width: "60",
        },
        {
          prop: "customerCode",
          label: $i18n.t("mesOtherCodePrinting.customerCode"),
          minWidth: "100",
          showOverflowTooltip: true,
        },
        {
          prop: "customerName",
          label: $i18n.t("mesOtherCodePrinting.customerName"),
          minWidth: "100",
          showOverflowTooltip: true,
        },
        {
          prop: "address",
          label: $i18n.t("mesOtherCodePrinting.address"),
          width: 250,
          showOverflowTooltip: true,
        },
        {
          prop: "contacts",
          label: $i18n.t("mesOtherCodePrinting.contacts"),
          width: 100,
          showOverflowTooltip: true,
        },
        {
          prop: "mobilePhone",
          label: $i18n.t("mesOtherCodePrinting.mobilePhone"),
          width: 120,
          showOverflowTooltip: true,
        },
        {
          prop: "telephone",
          label: $i18n.t("mesOtherCodePrinting.telephone"),
          width: 130,
          showOverflowTooltip: true,
        },
        {
          prop: "customerTypeValue",
          label: $i18n.t("mesOtherCodePrinting.customerTypeValue"),
          width: 120,
          showOverflowTooltip: true,
          optionProp: {
            value: "value",
            label: "description",
          },
          option: async (data) => {
            const list = await getCustomerTypeValueList();
            return list.data.result;
          },
        },
        {
          prop: "qualityType",
          label: $i18n.t("mesOtherCodePrinting.qualityType"),
          optionProp: {
            value: "value",
            label: "description",
          },
          option: async (data) => {
            const list = await getQualityTypeList();
            return list.data.result;
          },
          minWidth: 100,
        },
      ],
    };
  },
  methods: {
    // 弹框表格，双击表格，或者点击确定 返回选中数据
    async getSelectCustomer(data) {
      delete this.printFormDataDialog.customerCode;
      delete this.printFormDataDialog.customerName;
      // 第一个入参为当前表单绑定的对象，第二个入参为要修改的字段名，第三个入参为选中数据中相应信息
      this.$nextTick(() => {
        this.$set(this.printFormDataDialog, "customerCode", data[0].customerCode);
        this.$set(this.printFormDataDialog, "customerName", data[0].customerName);
        delete this.printFormDataDialog.codeStrategy;
        this.getPrintInfo(this.printFormDataDialog.codeType);
      })
    },
    // 物料查询dialog底部取消和确定按钮事件
    changeCustomerDialog(data) {
      data.name === $i18n.t('common.ok') && this.getSelectCustomer(data.rows);
      this.customerDialogVisible = false;
    },
  },
};
